# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=nerd-fonts
pkgver=2.1.0
pkgrel=9
pkgdesc="Iconic font aggregator, collection and patcher"
url="https://nerdfonts.com"
arch="noarch"
license="MIT AND OFL-1.1 AND Apache-2.0"
options="!check"  # no testsuite provided
builddir="$srcdir"

# If <fontname> is empty, <zipname> will be used instead.
# <origname> is used only for pkgdesc and it may be empty.
# "~" will be replaced with " "
# <id>,<zipname>,<fontname>,<origname>
_fonts="
	anonymous-pro,AnonymousPro,Anonymice,Anonymous~Pro
	arimo,Arimo,,
	bitstream-vera-sans-mono,BitstreamVeraSansMono,Bitstream~Vera~Sans~Mono,
	cascadia-code,CascadiaCode,Caskaydia~Cove,Cascadia~Code
	dejavu-sans-mono,DejaVuSansMono,DejaVu~Sans~Mono,
	droid-sans-mono,DroidSansMono,Droid~Sans~Mono,
	fira-code,FiraCode,Fira~Code,
	fira-mono,FiraMono,Fira~Mono,
	go-mono,Go-Mono,Go~Mono,
	hack,Hack,,
	hasklig,Hasklig,Hasklug,Hasklig
	hermit,Hermit,Hurmit,Hermit
	ia-writer,iA-Writer,iM~Writing,iA~Writer
	ibm-plex-mono,IBMPlexMono,Blex~Mono,IBM~Plex~Mono
	inconsolata,Inconsolata,,
	iosevka,Iosevka,,
	jetbrains-mono,JetBrainsMono,JetBrains~Mono,
	liberation-mono,LiberationMono,Literation~Mono,Liberation~Mono
	meslo,Meslo,,
	monofur,Monofur,monofur,
	mononoki,Mononoki,mononoki,
	overpass,Overpass,,
	share-tech-mono,ShareTechMono,Shure~Tech~Mono,Share~Tech~Mono
	source-code-pro,SourceCodePro,Sauce~Code~Pro,Source~Code~Pro
	space-mono,SpaceMono,Space~Mono,
	terminus,Terminus,Terminess,Terminus
	tinos,Tinos,,
	ubuntu-mono,UbuntuMono,Ubuntu~Mono,
	ubuntu,Ubuntu,,
	victor-mono,VictorMono,Victor~Mono,
	"
depends=""
subpackages=""
source=""
for _font in $_fonts; do
	_pkgname="font-${_font%%,*}-nerd"
	_filename=${_font#*,}; _filename=${_filename%%,*}

	depends="$depends $_pkgname"
	subpackages="$subpackages $_pkgname:_subpackage:noarch"
	source="$source $_pkgname-$pkgver.zip::https://github.com/ryanoasis/nerd-fonts/releases/download/v$pkgver/$_filename.zip"
done

prepare() {
	default_prepare

	rm ./*Windows\ Compatible.*

	# This is probably a mistake, there's both Fira and Fura.
	# https://github.com/ryanoasis/nerd-fonts/pull/356
	rm ./Fura\ Mono*.otf
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local id=${subpkgname#font-}; id=${id%-nerd}

	local IFS_OLD=$IFS IFS=','
	set -- $(printf '%s\n' "$_fonts" | grep "^\s*$id," | tr '~' ' ')
	if [ $# -lt 2 ]; then
		error "$id was not found in \$_fonts or wrong entry!"
		return 1
	fi
	IFS=$IFS_OLD

	local fontname=${3:-$2}
	local origname=${4-}
	depends="fontconfig"
	pkgdesc="$fontname Nerd Font${origname:+" (modified $origname Font)"}"

	# for backward compatibility (Alpine <3.16)
	case "$subpkgname" in
		font-ibm-plex-mono-nerd) provides="font-ibm-plex-nerd=$pkgver-r$pkgrel";;
		font-libertion-mono-nerd) provides="font-liberation-nerd=$pkgver-r$pkgrel";;
		font-ubuntu-nerd) depends="$depends font-ubuntu-mono-nerd";;
	esac

	cd "$builddir"
	install -Dm644 ./"$fontname"*.*tf -t "$subpkgdir"/usr/share/fonts/${subpkgname#font-}/
}

sha512sums="
761bb318e2f1a2f139c92aa793cf90156f892103233441632d88b13c6aa02c98f8704ecf510d44f9e9f7435896d16a81d720d65d1cd225c20271d769fd11305e  font-anonymous-pro-nerd-2.1.0.zip
c947c27766fd5f4725792d5745cc405b268f9c326da260c97af80ee729443ff39ad9a97fc4f122143ab2306fddedd5e8b55c13e4b3d90d3f65bf4d8559742dc1  font-arimo-nerd-2.1.0.zip
00c361c4eaabf81568083de29465deb80be27d2b5c6e00befe3478a5de23f6174ba9d295b47131ce067bb6e5524d40971ca2b5e7e827c21d91843ef0982f058f  font-bitstream-vera-sans-mono-nerd-2.1.0.zip
43422e7b075a8ae2d9eb77c5bf05cb26c590a1ac288731bdfb84dd1619038a0dd011546f1bcea7c436bc50d25a0a87cb7158c50eb37ed856bfa8757409b9259a  font-cascadia-code-nerd-2.1.0.zip
50b03224f43a319fe9db8a0845f5114811d8278b65d2ae1018f3529cad8ede1315438389ab132124b499ddbf779e0b4b195cef7e17dd0a3dc9c40657eed0ce1b  font-dejavu-sans-mono-nerd-2.1.0.zip
d5977e40b4c892564d322f828d80cdd9e2bf516d790cc4eb6f691cbae6dbc316cb0b0c1afece9a76d8d74c8ee79f7464feab980e6c835aaf848303562be80f5a  font-droid-sans-mono-nerd-2.1.0.zip
30f085ec033910aad006684ec180d69a89b2feb4b65a98d65d41b4c7262c14b6361ead37869aea16d0858a9e40fb955a4da981006785cc018d4315dcf8ef3fac  font-fira-code-nerd-2.1.0.zip
7bf6bed10d044ff487cc4c0137159180dc150fbb827e87359d89a29cc0eb9e6484b40434968a4c6ba96e2d54933db826b5f2d7f421ba914decda5c2d3497803e  font-fira-mono-nerd-2.1.0.zip
27eed9df1161564db22278b88492e30976dfbc8783bcfda6324c3dad3246f5d1466b2d318b7fbaa641baf410afbc7b362f310e410484dbead9d2f0e73de03ea1  font-go-mono-nerd-2.1.0.zip
fa545a32df4a94ba760378835d3b1d819a099d938a8dbfdc02d7712653a62893c7c1d67cd465ae96f2d8fe0b6094b5134c7342325e776709ac44749baef562e5  font-hack-nerd-2.1.0.zip
42e28b895795b3d1045265e6a9ea910103c2ad1f2ce88fdc21fefbf4db1e2fd46ab7e8e83417a5d8990041cae515e477b2d911a9603a4b55d81e0acc4797d832  font-hasklig-nerd-2.1.0.zip
caf9026646ea1756c0c3d4f5ef08b2329ce10f6bfeefd7a4c7cfba1ac16c85e08103cd05fe4ba9c34fc6f35bb1a5a8830053dc5f90f153410fec12ef134bf84a  font-hermit-nerd-2.1.0.zip
6fc219e954295fe4cc1a778141aa464f2b08d73def4c3428e875502d7c1cce1f2d5a4f178a83641e1e4b5d5c45eb406f11ab7858723894dd0bf4ec5e08775adf  font-ia-writer-nerd-2.1.0.zip
a4d6038e2c87cd481e29204adfb870b7af996d56a101bf7b8ef56682083888a63f48109c6d0be0b9b81ea2ebb6ce7e9c9ee0ad8006fed806ff3f9e4c6ddefe67  font-ibm-plex-mono-nerd-2.1.0.zip
c6b3a896543fb92df8ad0f8e3aede04ed5f17a3f61bcaf8146e8c0d872cb1a985226cd7062487a95f23ab168fdd5c8f4d7edf8818571c6e7dc3b9f4a0069e34d  font-inconsolata-nerd-2.1.0.zip
f97624aa018012313d1b496629a0db42c6b7f23eb473d71791445bbb7e1662335f846a37ee90d162e3eefee429169dd059407db0270ef5f327b9053e61417d8c  font-iosevka-nerd-2.1.0.zip
effc1a81670c37b07f17f1c756a480091c777f6074b59cd6eefd09c8d5210b529de3c41e9cedf4992aacd9fe5bb3a5b331411bfe5b2b6f0eb8680a8e852247c2  font-jetbrains-mono-nerd-2.1.0.zip
9a2fbd17c9af420b27dccbd6f4e3e2af133cce91e549d8427d8a8d78e825e1b79495884c18c13b189e7a8d7b58bb3e7029e132ac6d79cac3cf0406d44e6f05c8  font-liberation-mono-nerd-2.1.0.zip
a75dc57f89b73594d9cc72728018cc801455762cf690c9e0b7c9cd0c71f7f1c0fbc09d1fca3a4b7ac13dab69f8cb1c35dda044752aa6ef9cf9aef0e7df6803c3  font-meslo-nerd-2.1.0.zip
392df23757ceff77278dda9afb7820a8807fbbc46dd1c1b46486fc697891b8b9dcc63288b64c83187b140bf85443fe8d1bbc8d0d0497ca1be0d6aa11d99f5ed5  font-monofur-nerd-2.1.0.zip
32875d5c1f2257d1f14a36b36ea767c371d4384f06861926cb3fd723952bd9339b65d65341e769ca06b00eaeca7163f0dceccd3e55e723e1b6c8c7438d4f40b8  font-mononoki-nerd-2.1.0.zip
f16a963cd65f4ebe23918571ffd49c1a0fca315040012d1600a3292e6a79a2c88181ddc5a252329c4edcc8a5b5bc3d08d23c8e12f36f469b2a8856345bef33ea  font-overpass-nerd-2.1.0.zip
731dee4a8b9fcf399495b858378dd34746f2e5a9ed67e69e98387c5e77af7342df518221327264c207d75df5cfd878734aecc6fc3b170cf2972d39083bec597d  font-share-tech-mono-nerd-2.1.0.zip
550884cd0b4ac89e3a63434f636548e468a68763eeebb378ce3ab23971ae68bf3d3bd825cdc2634340da05e1b3712a3220c6cf875c36d946430add216cbfe709  font-source-code-pro-nerd-2.1.0.zip
9c0abc645b0db737f6f648d0d93f5fab1c7d0cb2e5d99e57de3476c61006a40faa430c6c1cc4cf23164d8e219c0419175e61b45b1780c7c43069aa0c89bb32eb  font-space-mono-nerd-2.1.0.zip
9189ac650b258528f51fa83d5bdd0c8f165c969d00b5a82ccdaf824684de188c8db10f92eb125591351aefcf1012cf198a07c643b3b8a3a7c2c8074e143cc926  font-terminus-nerd-2.1.0.zip
9ffa9b3689eddf5f2f22ac36018d0ac7c7cf26ffbc31b6865d7f316dd25f345480425cfc5488e5ac0866b7db5ead727dbf28a711b89c4af04d5a2d05a5bf3550  font-tinos-nerd-2.1.0.zip
32b8bd58f95552d9d7b50bf8047d5025d240f7f1ea99826c0257427a4a4c7bf811517bfb2416c1adfc2379429455c0b06fcbc401b46ee9b09b0249d64f44a2fa  font-ubuntu-mono-nerd-2.1.0.zip
ae939dff1d3854c7945f21b520e8cd8b5fa143f861e5911be492d1cad14a9cfc07e77ce2314af093702ab2ebbbfee7f69ac8faf95b8cc96cad257452870faf03  font-ubuntu-nerd-2.1.0.zip
394e823ed12fc3975d26dfcf3a3c1a0df3150b7160675c7c64d6756a67e695f6ae4b1daabbcaaac4f5abaaaa3cc71a0f3b635f93cd93b4a9801d7b32c8f3b949  font-victor-mono-nerd-2.1.0.zip
"
